//
//  FQDUserCenterRadarCell.m
//  FakeQDaily
//
//  Created by mewxiv on 9/27/16.
//  Copyright © 2016 Xensius. All rights reserved.
//

#import "FQDUserCenterRadarCell.h"
#import "FQDUserRadar.h"

NSString *const FQDUserCenterRadarCellActionTouchCaptionRadarItemInfoKey = @"FQDUserCenterRadarCellActionTouchCaption";

@interface FQDUserCenterRadarCell ()

@property (nonatomic, strong) FQDUserRadar *radar;

@end

@implementation FQDUserCenterRadarCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self prepareCell];
    }
    return self;
}

- (void)prepareCell
{
    _radar = [[FQDUserRadar alloc] initWithFrame:self.contentView.bounds];
    _radar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    _radar.radarItems = self.radarItems;
    [self.contentView addSubview:_radar];
    
    WeakSelf;
    [_radar setLoginBlock:^(id sender) {
        if (weakSelf.delegate) {
            [weakSelf.delegate collectionViewCell:weakSelf actionType:FQDUserCenterRadarCellActionLogin
                                    actionControl:sender userInfo:nil];
        }
    }];
    [_radar setTouchCaptionBlock:^(id sender, FQDRadarItem *radarItem) {
        if (weakSelf.delegate) {
            NSDictionary *userInfo = @{
                FQDUserCenterRadarCellActionTouchCaptionRadarItemInfoKey : radarItem
            };
            [weakSelf.delegate collectionViewCell:weakSelf actionType:FQDUserCenterRadarCellActionTouchCaption
                                    actionControl:sender userInfo:userInfo];
        }
    }];
}

- (void)setRadarItems:(NSArray<FQDRadarItem *> *)radarItems
{
    _radarItems = radarItems;
    
    self.radar.radarItems = radarItems;
}

+ (NSString *)reuseId
{
    return @"FQDUserCenterRadarCell";
}

@end
